Skip to content

Add filecache to git plugin FileContent with configurable TTL#2798

Merged
Lagoja merged 4 commits intomainfrom
jl/github-cache-backoff-env-variable-not-working-for-githttps
Mar 24, 2026
Merged

Add filecache to git plugin FileContent with configurable TTL#2798
Lagoja merged 4 commits intomainfrom
jl/github-cache-backoff-env-variable-not-working-for-githttps

Conversation

@Lagoja
Copy link
Collaborator

@Lagoja Lagoja commented Mar 23, 2026

Summary

When we implemented the new git+https plugins feature in the last release, we did not configure it to use the DEVBOX_X_GITHUB_PLUGIN_CACHE_TTL env var to set TTL for the plugin. The git plugin's FileContent method was cloning the plugin repo on every call. This adds caching using filecache (matching the github plugin pattern), with TTL controlled by DEVBOX_X_GITHUB_PLUGIN_CACHE_TTL env var.

How was it tested?

Added 3 tests:

  • Cache hit (TestGitPluginFileContentCache) — Clones from a local bare repo, then deletes the repo on disk and calls FileContent again. The second call succeeds, proving it’s served from cache rather than attempting a fresh clone.

  • TTL expiry via env var (TestGitPluginFileContentCacheRespectsEnvVar) — Sets DEVBOX_X_GITHUB_PLUGIN_CACHE_TTL=1ns so entries expire immediately, clones once, deletes the repo, then calls FileContent again. The second call fails because the expired cache entry forces a re-clone against the now-deleted repo. This proves the env var controls cache lifetime.

  • Invalid TTL (TestGitPluginFileContentCacheInvalidTTL) — Sets the env var to "not-a-duration" and verifies FileContent returns a parse error before attempting any clone.

Will also test functionality via a dev release.

Is this backwards compatible?

Yes

The git plugin's FileContent method was cloning the repo on every call.
This adds caching using filecache (matching the github plugin pattern),
with TTL controlled by DEVBOX_X_GITHUB_PLUGIN_CACHE_TTL env var.

Includes tests for cache hit, TTL expiry, and invalid TTL handling.
@Lagoja Lagoja requested a review from Copilot March 23, 2026 02:25
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds file-based caching for gitPlugin.FileContent so git+https plugin repos aren’t cloned on every read, with cache TTL controlled by DEVBOX_X_GITHUB_PLUGIN_CACHE_TTL.

Changes:

  • Add a filecache-backed cache for git plugin FileContent, with TTL read from DEVBOX_X_GITHUB_PLUGIN_CACHE_TTL.
  • Add tests covering cache hit behavior, TTL expiry behavior, and invalid TTL parsing.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.

File Description
internal/plugin/git.go Introduces filecache for FileContent and reads TTL from env var.
internal/plugin/git_test.go Adds integration-style tests using a local bare git repo to validate cache/TTL behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Lagoja and others added 3 commits March 23, 2026 16:30
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: John Lago <750845+Lagoja@users.noreply.github.com>
Use ttl.String() instead of raw env var in cache keys to avoid
path-separator injection and trailing slashes. Add t.Skip guard
in setupLocalGitRepo for CI environments without git.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@Lagoja Lagoja merged commit f82a364 into main Mar 24, 2026
24 checks passed
@Lagoja Lagoja deleted the jl/github-cache-backoff-env-variable-not-working-for-githttps branch March 24, 2026 00:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants